﻿// (c) Copyright Damian Mehers http://damianblog.com/
// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace MceFM.Last {
  class Tracer : TraceListener {
    readonly List<string> lines = new List<string>();
    readonly StringBuilder currentLine = new StringBuilder();
    private int maxLines = 2000;

//    public Tracer(string name) : base(name) {}

    public int MaxLines {
      get { return maxLines; }
      set { maxLines = value; }
    }

    public override void Write(string message) {
      currentLine.Append(message);
    }

    public override void WriteLine(string message) {
      lines.Add(currentLine + message);
      currentLine.Length = 0;
      while(lines.Count > maxLines) {
        lines.RemoveAt(0);
      }
    }

    public string[] GetTrace() {
      return lines.ToArray();
    }
  }
}
